﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// pour pouvoir utiliser le framework de test unitaires..*
using NUnit.Framework;

// pour pouvoir utiliser nos objets métier.
using AFCEPF.BankApplication.BLL;
// pour pouvoir utiliser nos objets d'accès aux données.
using AFCEPF.BankApplication.DAL;
// Pour pouvoir utiliser nos objets Mock et utilitaires.
using AFCEPF.BankApplication.Tests.Utilities;

namespace AFCEPF.BankApplication.Tests
{
    [TestFixture]
    class Test_AbstractSqlGenerator
    {
        AbstractSqlGenerator _generator;
        Person _person;
        private int _expectedYear;

        [SetUp]
        public void SetUp()
        {
            _person = new Person()
            {
                Name = "toto",
                FirstName = "titi",
                YearOfBirth = DateTime.Now.Year - 10
            };

            _expectedYear = DateTime.Now.Year - 10;

            // Gets the Sql Generator..
            _generator =  _person.DbAccessor.SqlGenerator;
        }


        [Test]
        public void Test_Method_Select()
        {
            string result   = _generator.GenerateSqlFor_Select();
            string expected = @"SELECT * FROM Personne WHERE Id = -1;";

            Assert.AreEqual(expected, result);
        }





        [Test]
        public void Test_Method_DELETE()
        {
            string result = _generator.GenerateSqlFor_Delete();
            string expected = @"DELETE FROM Personne WHERE Id = -1;";

            Assert.AreEqual(expected, result);
        }

        [Test]
        public void Test_Method_Update()
        {
            string result = _generator.GenerateSqlFor_Update();            
            string expected = @"UPDATE Personne SET Nom='TOTO', Prénom='titi', AnnéeNaissance=" + _expectedYear +" WHERE Id=-1;";
            Assert.AreEqual(expected, result);
        }

        

        [Test]
        public void Test_Method_Insert()
        {
            string result = _generator.GenerateSqlFor_Insert();
            string expected = @"INSERT INTO Personne VALUES ('TOTO', 'titi', "+ _expectedYear +") ;";
            Assert.AreEqual(expected, result);

        }



    }
}
